﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Windows.Forms;

public partial class String2 : Form
{
    StringBuilder sb;

    public String2()
    {
        InitializeComponent();
        sb = new StringBuilder();
    }

    private void String1_Load(object sender, EventArgs e)
    {
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (this.textBox1.Text == "")
        {
            MessageBox.Show("填数据库");
            return;
        }

        //string s = "";
        string s1 = this.richTextBox1.Text;
        char[] split = new char[] { '\n' };
        string[] temp1 = s1.Split(split);
        List<string> temp = new List<string>();

        for (int i = 0; i < temp1.Length; i++)
        {
            if (temp1[i].Trim() != "")
            {
                temp.Add(temp1[i].Trim());
            }
        }

        string table = this.textBox1.Text;

        for (int i = 0; i < temp.Count; i++)
        {
            if (temp[i].Trim() != "")
            {
                string ss = "string " + temp[i] + " = Request[\"" + temp[i] + "\"] == null ? \"\" : Request[\"" + temp[i] + "\"];";

                sb.Append(ss);
                sb.Append("\n");
            }
        }

        sb.Append("\n");
        sb.Append("\n");

        string sql1 = "\"select ";

        string sql = "\"UPDATE " + table + " SET ";

        string strvar = "";

        string bianli = "";
        bianli += "DataTable dt = this.getData();";
        bianli += "\n";
        bianli += "DataRow dr;";
        bianli += "\n";
        bianli += " for (int i = 0; i < dt.Rows.Count; i++)";
        bianli += "\n";

        bianli += "{";
        bianli += "\n";

        bianli += "dr = dt.Rows[i];";
        bianli += "\n";

        string yemian = "";

        string yemian1 = "";

        for (int i = 0; i < temp.Count; i++)
        {
            yemian += "<%=" + temp[i] + "%>";
            yemian += "\n";

            yemian1 += "<%= dr[\"" + temp[i] + "\"].ToString() %>";
            yemian1 += "\n";

            if (i == temp.Count - 1)
            {
                sql += "" + temp[i] + " = '\" + " + temp[i] + " + \"';\"";
                sql1 += temp[i] + " from " + table + "\";";
            }
            else
            {
                sql += "" + temp[i] + " = '\" + " + temp[i] + " + \"',";
                sql1 += temp[i] + ",";
            }

            strvar += "public string " + temp[i] + ";\n";

            bianli += temp[i] + "=dr[\"" + temp[i] + "\"].ToString() ;";
            bianli += "\n";

            //sb.Append("\n");
        }

        //*************************************************************
        //Append
        //*************************************************************

        sb.Append(yemian1);
        sb.Append("\n");
        sb.Append("\n");

        sb.Append(sql);
        // sql = "UPDATE "+table+" SET Indentity = '" + Indentity + "', technical_level

        sb.Append("\n");
        sb.Append("\n");

        sb.Append(sql1);

        sb.Append("\n");
        sb.Append("\n");

        sb.Append(strvar);

        sb.Append("\n");
        sb.Append("\n");

        bianli += "}";
        sb.Append(bianli);

        sb.Append("\n");
        sb.Append("\n");

        sb.Append(yemian);

        this.richTextBox2.Text = sb.ToString();
        sb.Length = 0;

        //*************************************************************
        //Append
        //*************************************************************
    }
}